import 'package:bxultimate/data/request/organization_request.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'state.dart';

class OrganizationSelectUserController extends GetxController {
  final OrganizationSelectUserState state = OrganizationSelectUserState();

  List<String>? checkIds = [];

  TDCheckboxGroupController checkboxGroupController =
      TDCheckboxGroupController();

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    getData();
  }

  void getData() async {
    state.userList =
        await OrganizationRequest.getStatisticsTaskMemberList(Get.arguments);
  }

  void handleSelect() {
    List<String> indexList = checkIds!.map((e) => e.split(":")[1]).toList();

    List<String> idcard = [];
    for (var i in indexList) {
      if (int.parse(i) - 1 < 0) {
        continue;
      }
      idcard.add(state.userList[int.parse(i) - 1].idcard!);
    }
    Get.back(result: idcard);
  }
}
